package quartzDemo;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;

public class QuartzDemo {

    public static void main(String[] args) throws SchedulerException {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

        //创建JobDetail的同时，同时创建一个Job实例，不直接接受一个Job实例，通过接受一个Job实现，new Instance()创建一个Job实例
        JobDetail jobDetail = JobBuilder
                .newJob(QuartzJob.class)
                .withIdentity("quartzJob","group")
                .build();

        CronTrigger trigger = TriggerBuilder
                .newTrigger()
                .withIdentity("quartzTrigger","group")
                .startAt(new Date())
                .withSchedule(CronScheduleBuilder.cronSchedule("0 * * * * ? *"))
                .build();

        scheduler.start();

        scheduler.scheduleJob(jobDetail,trigger);


    }
}
